﻿using Architecture.API.Application.TraceabilityCommand.TraceabilitiesCommand;
using MediatR;
using Traceability.Domain.BreedDomain;
using Traceability.Domain.Service.SlaughterServices;
using Traceability.Domain.Service.TraceabilitiesServices;

namespace Architecture.API.Application.TraceabilityCommandHandler.TraceabilitiesCommandHandler
{
    /// <summary>
    /// 添加免疫命令处理器
    /// </summary>
    public class AddTraceabilitiesCommandHandler : IRequestHandler<AddTraceabilitiesCommand, int>
    {
        /// <summary>
        /// 免疫服务
        /// </summary>
        protected readonly ITraceabilitiesService traceabilitiesService;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="traceabilitiesService">免疫服务</param>
        public AddTraceabilitiesCommandHandler(ITraceabilitiesService traceabilitiesService)
        {
            this.traceabilitiesService = traceabilitiesService;
        }

        /// <summary>
        /// 添加免疫信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<int> Handle(AddTraceabilitiesCommand request, CancellationToken cancellationToken)
        {
            return await traceabilitiesService.AddTraceabilities(new Traceabilities() { FeedingDays = request.FeedingDays, ImmuneSystem = request.ImmuneSystem, ImmuneMethods = request.ImmuneMethods, ProductionBatch=request.ProductionBatch,ShoppingId=request.ShoppingId,CreatedBy=request.CreatedBy,CreatedDate=DateTime.Now});
        }
    }
}
